home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / parser / s_yylex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  2.8 KB  |  145 lines

  1. # include    <ingres.h>
  2. # include    "scanner.h"
  3. # include    <errors.h>
  4.  
  5. struct special    Tokens;            /* special tokens table */
  6. struct optab    Optab[];        /* operator table */
  7. struct optab    Keyword[];        /* keyword table */
  8. struct lastok    Lastok;
  9. int        Opcode;            /* opcode for current token */
  10. int        Lcase;            /* UPPER->lower conversion flag */
  11. int        Pars;            /* flag for call to getcvar or not */
  12. int        Newline;        /* set if last char read was a newline */
  13. int        Cflag;            /* set if line of C-code recognized */
  14. int        Keyent;            /* number of entries in the Keyword table */
  15. extern char    Cmap[];
  16.  
  17. char        Sbuf[SBUFSIZ];        /* symbol table buffer */
  18.  
  19. /*
  20. ** YYLEX
  21. ** This is the control program for the scanner (lexical analyzer).
  22. ** Each call to yylex() returns a token for the next syntactic unit.
  23. ** If the object is of type I2CONST, I4CONST, F8CONST, SCONST or NAME, that
  24. ** object will also be entered in the symbol table, indexed by 'yylval'.
  25. ** If the object is not one of these types, yylval is the opcode field of
  26. ** the operator or keyword tables.
  27. ** The end-of-file token is zero.
  28. */
  29. yylex()
  30. {
  31.     register char    chr;
  32.     register int    rtval;
  33.  
  34.     rtval = -1;
  35.     Lastok.tokop = 0;
  36.     /* GET NEXT TOKEN */
  37.     do
  38.     {
  39.         if((chr = get_scan(NORMAL)) <= 0)
  40.         {
  41. #            ifdef    xSTR2
  42.             tTfp(72, 8, "end-of-file\n");
  43. #            endif
  44.             rtval = 0;
  45.             break;
  46.         }
  47.         switch(Cmap[chr])
  48.         {
  49.           case ALPHA:
  50.             rtval = name(chr);
  51.             break;
  52.  
  53.           case NUMBR:
  54.             rtval = number(chr);
  55.             break;
  56.  
  57.           case OPATR:
  58.             if ((rtval = operator(chr)) == 0)
  59.                 rtval = -1;
  60.             break;
  61.  
  62.           case PUNCT:
  63.             continue;
  64.  
  65.           case CNTRL:
  66.             /* already converted number ? */
  67.             if (Pars)
  68.                 switch (chr)
  69.                 {
  70.                   case CVAR_I2:
  71.                     rtval = getcvar(Tokens.i2const, 2);
  72.                     break;
  73.  
  74.                   case CVAR_I4:
  75.                     rtval = getcvar(Tokens.i4const, 4);
  76.                     break;
  77.  
  78.                   case CVAR_F8:
  79.                     rtval = getcvar(Tokens.f8const, 8);
  80.                     break;
  81.  
  82.                   case CVAR_S:
  83.                     rtval = getcvar(Tokens.sconst, 0);
  84.                     break;
  85.  
  86.                   default:
  87.                     printf("funny character 0%o ingnored\n", chr);
  88.                     continue;
  89.                 }
  90.             break;
  91.           default:
  92.             syserr("invalid type in yylex()");
  93.         }
  94.     }  while (rtval == -1);
  95.     if (rtval == 0)
  96.     {
  97.         Lastok.tokop = GOVAL;
  98.         Lastok.tok = 0;
  99.         Lastok.toktyp = 0;
  100.     }
  101.     return (rtval);
  102. }
  103.  
  104.  
  105. getcvar(type, len)
  106. int    type;
  107. int    len;
  108. {
  109.     extern char    *yylval;
  110.     extern char    *syment();
  111.     register int    save;
  112.     char        buf[MAXSTRING + 1];
  113.  
  114.     save = Lcase;
  115.     Lcase = 0;
  116.     yylval = buf;
  117.     if (len)
  118.         while ((yylval - buf) < len)
  119.             *yylval++ = get_scan(NORMAL);
  120.     else
  121.     {
  122.         do
  123.         {
  124.             *yylval = get_scan(NORMAL);
  125.             if ((yylval - buf) > MAXSTRING)
  126.             {
  127.                 Lcase = save;
  128.                 par_error(STRLONG, WARN, 0);
  129.             }
  130.             if (Cmap[*yylval] == CNTRL && *yylval != '\0')
  131.             {
  132.                 Lcase = save;
  133.                 /* control char in string from equel */
  134.                 par_error(CNTRLCHR, WARN, 0);
  135.             }
  136.         } while (*yylval++);
  137.         len = yylval - buf;
  138.     }
  139.     Lcase = save;
  140.     yylval = syment(buf, len);
  141.     Lastok.tok = yylval;
  142.     Lastok.toktyp = type;
  143.     return (type);
  144. }
  145.